#include "QtUI/ProjectInformationWidget.qth"
#include "QtUI/ProjectInformationWidget.moh"
#include "QtUI/ProjectGeneralInfoWidget.qth"
#include "QtUI/ConnectionListWidget.qth"
#include <QtGui/QListWidget>
#include <QtGui/QStackedWidget>
#include <QtGui/QHBoxLayout>

namespace QtUI
{

ProjectInformationWidget::ProjectInformationWidget( const Storage::ConnectionConfigCollection& connCfgColl, QWidget* pParent)
	: QWidget( pParent)
{
	QHBoxLayout* pLayout = new QHBoxLayout();
	this->setLayout( pLayout);

	pContentsList_ = new QListWidget;
	pContentsList_->setViewMode(QListView::IconMode);
	pContentsList_->setIconSize(QSize(96, 84));
	pContentsList_->setMovement(QListView::Static);
	pContentsList_->setMaximumWidth(128);
	pContentsList_->setSpacing(12);
	pLayout->addWidget( pContentsList_);

	pPagesWidget_ = new QStackedWidget;
	pLayout->addWidget( pPagesWidget_);

	// Adding pages
	// General Info
	QListWidgetItem* pGeneralInfoItem = new QListWidgetItem;
	pGeneralInfoItem->setTextAlignment( Qt::AlignHCenter);
	pGeneralInfoItem->setText( tr( "General Information",  "Title for configuration item in content list"));
	pContentsList_->addItem( pGeneralInfoItem);
	pGeneralInfoWidget_ = new ProjectGeneralInfoWidget;
	pPagesWidget_->addWidget( pGeneralInfoWidget_);

	// Connection
	QListWidgetItem* pConnInfoItem = new QListWidgetItem;
	pConnInfoItem->setTextAlignment( Qt::AlignHCenter);
	pConnInfoItem->setText( tr( "Connection", "Title for connection item in content list"));
	pContentsList_->addItem( pConnInfoItem);
	pConnListWidget_ = new ConnectionListWidget( connCfgColl);
	pPagesWidget_->addWidget( pConnListWidget_);

	connect( pContentsList_,
		SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)),
		this, SLOT(changePage( QListWidgetItem *, QListWidgetItem*)));

	pContentsList_->setCurrentRow( 0);
}

// ---------------------------------------------------------------------------------------------------------------------

void ProjectInformationWidget::changePage( QListWidgetItem* current, QListWidgetItem* previous)
{
	if( NULL == current)
		current = previous;

	pPagesWidget_->setCurrentIndex( pContentsList_->row( current));
}

// ---------------------------------------------------------------------------------------------------------------------

QString ProjectInformationWidget::projectName() const
{
	return pGeneralInfoWidget_->projectName();
}

// ---------------------------------------------------------------------------------------------------------------------

void ProjectInformationWidget::setProjectName( const QString& newName)
{
	pGeneralInfoWidget_->setProjectName( newName);
}

// ---------------------------------------------------------------------------------------------------------------------

QString ProjectInformationWidget::description() const
{
	return pGeneralInfoWidget_->description();
}

// ---------------------------------------------------------------------------------------------------------------------

void ProjectInformationWidget::setDescription( const QString& newDescription)
{
	pGeneralInfoWidget_->setDescription( newDescription);
}

// ---------------------------------------------------------------------------------------------------------------------

const Storage::ConnectionConfig* ProjectInformationWidget::connectionConfig() const
{
	return pConnListWidget_->selectedConnCfg();
}

// ---------------------------------------------------------------------------------------------------------------------

void ProjectInformationWidget::setConnectionConfig( const Storage::ConnectionConfig* pConnCfg)
{
	pConnListWidget_->selectConnCfg( pConnCfg);
}

} // namespace QtUI
